﻿#pragma execution_character_set("utf-8")
#include "navigationwidget.h"
#include "ui_navigationwidget.h"
#include <QMessageBox>
#include <QApplication>
/**
 * @brief 导航界面构造函数
 * @details 初始化界面组件并连接信号槽，加载预置地图文件
 * 地图文件路径由可执行文件目录拼接"/text.map2"构成
 */
NavigationWidget::NavigationWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::NavigationWidget)
{
    ui->setupUi(this);
    connect(ui->widget,SIGNAL(sendListClear()),this,SLOT(acceptListClear()));
    connect(ui->widget,SIGNAL(sendListAdd(QString)),this,SLOT(acceptListAdd(QString)));
    connect(ui->widget,SIGNAL(sendMinPath(QString)),this,SLOT(acceptMinPath(QString)));

    connect(ui->widget,SIGNAL(sendMapCorePl(QStringList)),this,SLOT(acceptMapCorePl(QStringList)));

    ui->widget->loadMap(QApplication::applicationDirPath()+"/text.map2");
}

NavigationWidget::~NavigationWidget()
{
    delete ui;
}

/**
 * @brief 执行路径查询操作····································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································································请求··············································································································································································································································································································  去··                                                                                                                                                                                                                                                                                     ····································································                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ·
 *                       ·
 * @details 验证起点终点有效性后触发路径查找算法
 * - 当起点终点不同时调用findAllPaths查找所有路径
 * - 相同地点时显示错误提示
 */
void NavigationWidget::on_pushButton_clicked()
{
    if( ui->comboBox_1->currentText()!= ui->comboBox_2->currentText()){
        ui->widget->findAllPaths(ui->comboBox_1->currentText(),ui->comboBox_2->currentText());
    }else{
        QMessageBox::information(this, "提示", "查询失败，起点和终点相同");
    }
}

void NavigationWidget::acceptListClear()
{
    ui->listWidget->clear();
}

void NavigationWidget::acceptListAdd(QString str)
{
    ui->listWidget->addItem(str);
}

/**
 * @brief 更新地点选择下拉框
 * @details 接收地图核心模块发送的地点列表，同步更新两个下拉框
 * @param p_list 有效地点名称列表，过滤空字符串后使用
 */
void NavigationWidget::acceptMapCorePl(QStringList p_list)
{
    ui->comboBox_1->clear();
    ui->comboBox_2->clear();

    for(int i = 0 ; i < p_list.size();i++){
        if(p_list.at(i).size() >=1 && !p_list.at(i).contains("路口")){
            ui->comboBox_1->addItem(p_list.at(i));
            ui->comboBox_2->addItem(p_list.at(i));
        }
    }
}

/**
 * @brief 显示最短路径结果
 * @details 格式化输出路径信息到文本编辑框
 * @param str 路径算法返回的格式化字符串，包含路径详情
 */
void NavigationWidget::acceptMinPath(QString str)
{
    qDebug()<<"acceptMinPath==="<<str;
    ui->textEdit->clear();
    ui->textEdit->append(str);
}


